import Vue from "vue";

export let store = Vue.observable({
  pageName: "", // 编辑的页面名称
  currentPage: {}, // 当前编辑的页面数据
  actionStep: [], // 操作记录(只记录5步用户操作)
  returnAction: [], // 回复操作
  currentAction: "", // 当前操作类型
  dragItem: null,
  currentComponent: {}, // 当前编辑的组件
  globalPages: [], // 全局页面数据
  currentComIndex: -1,
  globalRef: null,
  themeConfig: {},
});
export let mutations = {
  setPageName(name) {
    store.pageName = name;
  },
  setCurrentPage(data) {
    store.currentPage = data;
  },
  pushActionStep(data) {
    if (store.actionStep.length >= 5) {
      store.actionStep.splice(4, 1, data);
      return;
    }
    store.actionStep.push(data);
  },
  setActionStep(data) {
    store.actionStep = data;
  },
  setDragItem(data) {
    store.dragItem = data;
  },
  setCurrentAction(data) {
    store.currentAction = data;
  },
  setCurrentComponent(data) {
    store.currentComponent = data;
  },
  setGlobalPages(data) {
    store.globalPages = data;
  },
  setCurrentComIndex(data) {
    store.currentComIndex = data;
  },
  setReturnAction(data) {
    store.returnAction = data;
  },
  setRef(data) {
    store.globalRef = data;
  },
  setThemeConfig(data) {
    store.themeConfig = data;
  },
};

export default {
  store,
  mutations,
};
